﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.Geodatabase;

namespace CanSWAT.ArcSWAT.Soil
{
    /// <summary>
    /// Util class to read value from a given row and given column
    /// </summary>
    class ArcGISRow
    {
        public static string ReadString(IRow r, string colName)
        {
            if (r == null) return "";
            int index = r.Fields.FindField(colName);
            if (index == -1) return "";
            if (System.DBNull.Value.Equals(r.get_Value(index))) return "";
            return r.get_Value(index).ToString();
        }

        public static double ReadDouble(IRow r, string colName)
        {
            string s = ReadString(r, colName);
            if (s.Length == 0) return 0.0;
            else
            {
                double v = 0.0;
                double.TryParse(s, out v);
                return v;
            }
        }

        public static int ReadInteger(IRow r, string colName)
        {
            return Convert.ToInt32(ReadDouble(r, colName));
        }
    }
}
